/*
** init_args.c for dayday in /home/dd/projs/dayday/srcs/client
** 
** Made by dd
** Login   <alletr_p@epitech.net>
** 
** Started on  Tue Jul 21 19:24:53 2009 dd
** Last update Tue Jul 21 22:10:11 2009 dd
*/

#include <assert.h>
#include <unistd.h>
#include <stdio.h>

#ifndef _GNU_SOURCE_
#define _GNU_SOURCE_
#include <getopt.h>
#include <string.h>
#endif

#include "client.h"

#define DONE_SIZE	6

int		init_args(t_all *all, int ac, char **av)
{
  int		i;
  int		d;
  char		c;
  char		done[DONE_SIZE];
  extern char	*optarg;
  extern t_args	gl_args[];

  d = 0;
  assert(all && av);
  memset(done, sizeof(done), 0);
  while ((c = getopt(ac, av, "i:p:w:h:f")) != EOF)
    {
      for (i = 0; gl_args[i].opt; i++)
	if (gl_args[i].opt == c)
	  {
	    if (strchr(done, c))
	      {
		print(STRERR_ARGS_DUPLICATED);
		return (FAILURE);
	      }
	    if (gl_args[i].f(all, optarg) == FAILURE)
	      return (FAILURE);
	    done[d++] = c;
	  }
    }
  return (init_args_noargs(all, done));
}
